<template>
    <div class="news-detail-container">
        <!-- 头部信息 -->
        <div class="news-header">
            <h1 class="news-title">{{ newsData.title }}</h1>
            <div class="news-meta">
                <span class="author">{{ newsData.author }}</span>
                <span class="time">{{ formatTime(newsData.createTime) }}</span>
                <span class="views">浏览: {{ newsData.viewCount }}</span>
            </div>
        </div>

        <!-- 幻灯片展示 -->
        <div v-if="newsData.isSlide" class="news-slider">
            <el-carousel height="400px" indicator-position="outside">
                <el-carousel-item v-for="(img, index) in newsData.slideImages" :key="index">
                    <a :href="newsData.slideLinks[index]" target="_blank">
                        <el-image :src="img" fit="cover" style="width: 100%; height: 100%"
                            :preview-src-list="newsData.slideImages" :initial-index="index" />
                    </a>
                </el-carousel-item>
            </el-carousel>
        </div>

        <!-- 基本信息 -->
        <div class="news-basic-info">
            <div class="info-item">
                <el-icon>
                    <Location />
                </el-icon>
                <span>活动地点: {{ newsData.location }}</span>
            </div>
            <div class="info-item">
                <el-icon>
                    <Clock />
                </el-icon>
                <span>活动时间: {{ formatDateTime(newsData.time) }}</span>
            </div>
            <div class="info-item">
                <el-icon>
                    <User />
                </el-icon>
                <span>主办单位: {{ newsData.sponsors.join('、') }}</span>
            </div>
        </div>

        <!-- 标签 -->
        <div class="news-tags">
            <el-tag v-for="(tag, index) in newsData.tags" :key="index" :type="['', 'success', 'info'][index % 3]"
                size="small">
                {{ tag }}
            </el-tag>
        </div>

        <!-- 内容区域 -->
        <div class="news-content">
            <h3>活动简介</h3>
            <p class="summary">{{ newsData.summary }}</p>

            <h3>活动详情</h3>
            <div class="detail-content" v-html="newsData.detail || newsData.content"></div>

            <h3 v-if="newsData.condition">参与条件</h3>
            <div class="conditions" v-if="newsData.condition">
                <p v-for="(item, index) in formatConditions(newsData.condition)" :key="index">
                    {{ index + 1 }}. {{ item }}
                </p>
            </div>
        </div>

        <!-- 相关图片 -->
        <div v-if="newsData.images.length > 0" class="news-images">
            <h3>活动图片</h3>
            <div class="image-grid">
                <el-image v-for="(img, index) in newsData.images" :key="index" :src="img" fit="cover" class="grid-image"
                    :preview-src-list="newsData.images" />
            </div>
        </div>

        <!-- 操作按钮 -->
        <div class="news-actions">
            <el-button type="primary" @click="handleJoin">立即报名</el-button>
            <el-button @click="handleShare">分享活动</el-button>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import {
    Location,
    Clock,
    User,
} from '@element-plus/icons-vue'
import dayjs from 'dayjs'

// 直接在组件内定义数据
const newsData = ref({
    id: 1,
    title: '2023年度校园科技文化节即将开幕',
    content: '第十五届校园科技文化节将于下月举行，本次文化节将涵盖科技创新、艺术展示、学术交流等多个领域。活动期间将举办50余场专题讲座、20项科技竞赛和10场文艺演出，预计参与师生超过5000人。欢迎全校师生积极参与，共同打造校园文化盛宴。',
    text: "<p>这里是HTML格式的详细内容</p>",
    author: '校团委',
    createTime: '2023-05-20 10:00:00',
    isSlide: true,
    slideImages: [
        'https://agoni-web.oss-cn-beijing.aliyuncs.com/slide1.jpg',
        'https://agoni-web.oss-cn-beijing.aliyuncs.com/slide2.jpg',
        'https://agoni-web.oss-cn-beijing.aliyuncs.com/slide3.jpg'
    ],
    slideLinks: [
        'https://www.bilibili.com/video/BV1fK4y1p7yN',
        'https://www.bilibili.com/video/BV1fK4y1p7yN',
        'https://www.bilibili.com/video/BV1fK4y1p7yN'
    ],
    viewCount: 10000,
    tags: ['科技', '文化', '活动'],
    sponsors: ['科技部', '教育部', '体育部'],
    location: '学校体育场',
    time: '2023-11-25 14:00:00',
    summary: '第十五届校园科技文化节将于下月举行，本次文化节将涵盖科技创新、艺术展示、学术交流等多个领域。活动期间将举办50余场专题讲座、20项科技竞赛和10场文艺演出，预计参与师生超过5000人。欢迎全校师生积极参与，共同打造校园文化盛宴。',
    detail: `
      <h4>活动背景</h4>
      <p>为促进校园科技创新文化建设...</p>
      <h4>活动亮点</h4>
      <ul>
        <li>前沿科技展示</li>
        <li>学生创新作品展览</li>
        <li>专家学术讲座</li>
      </ul>
    `,
    images: [
        'https://agoni-web.oss-cn-beijing.aliyuncs.com/activity1.jpg',
        'https://agoni-web.oss-cn-beijing.aliyuncs.com/activity2.jpg'
    ],
    condition: `1. 参赛选手需提前进行体检
  2. 参赛选手须持有有效身份证件
  3. 参赛选手须遵守比赛规则
  4. 参赛选手须配合指导老师指导`
})

// 格式化时间
const formatTime = (timeStr: string) => {
    return dayjs(timeStr).format('YYYY-MM-DD HH:mm')
}

// 格式化日期时间
const formatDateTime = (timeStr: string) => {
    return dayjs(timeStr).format('YYYY年MM月DD日 HH:mm')
}

// 格式化参与条件
const formatConditions = (condition: string) => {
    return condition.split('\n').filter(item => item.trim())
}

// 操作处理
const handleJoin = () => {
    console.log('报名活动:', newsData.value.id)
    // 这里可以跳转到报名页面或弹出报名表单
}

const handleShare = () => {
    console.log('分享活动:', newsData.value.id)
    // 这里可以实现分享功能
}
</script>

<style scoped lang="scss">
/* 保持与之前相同的样式 */
.news-detail-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.news-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;

    .news-title {
        font-size: 24px;
        color: #333;
        margin-bottom: 12px;
    }

    .news-meta {
        display: flex;
        gap: 20px;
        font-size: 14px;
        color: #666;

        .author {
            color: var(--el-color-primary);
        }
    }
}

.news-slider {
    margin-bottom: 24px;
    border-radius: 8px;
    overflow: hidden;
}

.news-basic-info {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;

    .info-item {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 14px;
        color: #666;

        .el-icon {
            color: var(--el-color-primary);
        }
    }
}

.news-tags {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.news-content {
    margin-bottom: 30px;
    line-height: 1.8;

    h3 {
        font-size: 18px;
        color: #333;
        margin: 24px 0 16px;
        padding-bottom: 8px;
        border-bottom: 1px solid #eee;
    }

    .summary {
        font-size: 16px;
        color: #444;
        margin-bottom: 20px;
    }

    .detail-content {
        font-size: 15px;
        color: #555;

        :deep(img) {
            max-width: 100%;
            border-radius: 4px;
            margin: 10px 0;
        }
    }

    .conditions {
        background: #f8f9fa;
        padding: 16px;
        border-radius: 8px;
        font-size: 14px;
        color: #555;
    }
}

.news-images {
    margin-bottom: 30px;

    .image-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 12px;
        margin-top: 16px;

        .grid-image {
            height: 180px;
            border-radius: 8px;
            cursor: pointer;
            transition: transform 0.3s;

            &:hover {
                transform: scale(1.02);
            }
        }
    }
}

.news-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px solid #eee;
}

/* 其他样式保持不变... */
</style>